<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_block_ListDashboardAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{
                //get all dashboards
		$dashBoardsArray = m_backoffice_services_DashBoardService::getInstance()->getBoards();
                //get user checked dashboards
                $user = f_document_Provider::getInstance()->getByModelAndUniqueId('users/User', $this->getUserContext()->getUser()->getUniqueId());
                $userDashBoardsArray = $user->getExtraParameter('dashboards');

                $checkedBoards = Array();
                //set checked array

                if(is_array($userDashBoardsArray))
                {
                    foreach($dashBoardsArray as $moduleName => $module)
                    {
                        foreach($module as $board)
                        {
                            if(in_array($moduleName.'_'.$board['title'], $userDashBoardsArray))
                                $checkedBoards[count($checkedBoards)] = 'checked';
                            else
                                $checkedBoards[count($checkedBoards)] = '';
                        }
                    }
                }

                $this->addToModel("checkeddashboards", $checkedBoards);
                $this->addToModel("dashboards", $dashBoardsArray);
                
		$this->setView('success');
	}
}